package com.carstop.model;

import java.util.List;
import java.util.Map;

public class CarStopService {
	private CarStopDAO_interface dao;
	public static Map<String, CarStopVO> carstopMap;

	static {
		if (carstopMap == null) {
			//1 = JNDI , other = JDBC
			carstopMap = getCarstopList(1);
		}
	}
	
	public CarStopService() {
		dao = new CarStopDAO();
	}
	
	public CarStopService(int type) {
		dao = new CarStopJDBCDAO();
	}
	
	public CarStopVO addArea(String stop_id, String name, String town_id,Double stop_longitude,Double stop_latitude) {

		CarStopVO carstopVO = new CarStopVO();

		carstopVO.setStop_id(stop_id);
		carstopVO.setName(name);
		carstopVO.setTown_id(town_id);
		carstopVO.setStop_longitude(stop_longitude);
		carstopVO.setStop_latitude(stop_latitude);
		
		dao.insert(carstopVO);

		return carstopVO;
	}

	public CarStopVO updateEmp(String stop_id, String name, String town_id,Double stop_longitude,Double stop_latitude) {

		CarStopVO carstopVO = new CarStopVO();

		carstopVO.setStop_id(stop_id);
		carstopVO.setName(name);
		carstopVO.setTown_id(town_id);
		carstopVO.setStop_longitude(stop_longitude);
		carstopVO.setStop_latitude(stop_latitude);
		dao.update(carstopVO);

		return carstopVO;
	}

	public void deleteEmp(String stop_id) {
		dao.delete(stop_id);
	}
	
	public static Map<String, CarStopVO> getCarstopList(int type) {
		// 1 = JNDI mode
		if (type == 1)
			return CarStopDAO.getCarstopList();
		else
			return CarStopJDBCDAO.getCarstopList();
	}

/*	public List<CarStopVO> getAll() {
		return dao.getAll();
	}*/
}
